<?php
/**
 * Config reader. Reads files
 * @author Kirill Egorov 2010l
 * @abstract
 * @package Config
 */
 abstract class Config_File extends Config_Abstract{

     public function __construct($name){
         parent::__construct($name);
         /**
          * Get cach frontend
          * @var Zend_Cache_Core
          */      
         $cache = Config::getCacheCore();
         /*
          * Check cache
          */
         if($cache && $data = $cache->load(md5($name))){
              $this->_data = $data;
              return;
         }
         
         if(!file_exists($name))
             throw new Exception('Config file '.$name.' is not exists.');
         
         /*
          * Read config from file
          */
         $data = $this->_readFile($name);
         if (is_array($data))
		 	 $this->_data = $data;
         else
         	 $this->_data = array();
         /*
          * Update cache
          */
         if($cache)
             $cache->save($this->_data, md5($name));
     }
     /**
      * Read config file 
      * @param string $name
      * @return array
      */
     abstract protected function _readFile($name);
     /**
      * Save config
      * @return boolean  success
      */
     abstract public function save();
}
